# encoding=utf-8
# MVVM架构的model，数据模型
# BingoLee 2024-04-17
from typing import Any


class Cache(object):
    """ 服务器数据以及本地首选项配置数据缓存 """

    def __init__(self):
        self.__comports = []
        self.__settings_data = {}
        self.__custom_at_cmds = {}
        self.__project_at_cmds = {}

    def get_comports(self) -> list:
        return self.__comports

    def update_comports(self, new_ports: list):
        self.__comports = new_ports

    def init_settings_data(self, data: dict):
        self.__settings_data = data

    def get_settings_data(self, key: str = None, default: Any = None) -> Any:
        return self.__settings_data.get(key, default) if key else self.__settings_data

    def init_custom_at_cmds(self, data: dict):
        self.__custom_at_cmds = data

    def get_custom_at_cmds(self) -> dict:
        return self.__custom_at_cmds

    def init_project_at_cmds(self, data: dict):
        self.__project_at_cmds = data

    def get_project_at_cmds(self) -> dict:
        return self.__project_at_cmds


cache = Cache()
